Skip to content

Conversation

@eemeli
Copy link
Member

@eemeli eemeli commented Oct 29, 2025

While putting together tc39/test262#4608, I validated the proposed spec text with a patched fork of FormatJS, and this identified a few places where the spec text needs to be updated:

  • Leading zeros need to be discarded, so we count '0012.3' to have three string digits. To do so in the syntax-directed operation, I introduce ZeroDigits as a new syntax rule.

  • An elided leading zero needs to be accounted for, so '.45' should count as having three string digits.

  • Changes in exponents that reduce the number of leading zeros need to also reduce the string digit count accordingly. This means that when formatted as a percentage, '0.06' should format as if it had only one string digit, rather than three. This adjustment needs to be done potentially twice, as style: 'percent' can be combined with notation: 'engineering' or notation: 'scientific'.

Ping @sffc, @gibson042, @jessealama, @ben-allen for reviews.

@eemeli eemeli requested a review from jessealama November 11, 2025 02:03
1. <del>Let _a_ be MV of |DecimalDigits|.</del>
1. <ins>If the |DecimalDigits| is present, then</ins>
1. <ins>Let _m_ be the number of code points in |DecimalDigits|.</ins>
1. <ins>Let _a_ be the MV of |NonZeroDigit| × 10<sup>_m_</sup> plus the MV of |DecimalDigits|.</ins>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we split up the calculation? E.g.

1. Let _d_ be the MV of |DecimalDigits|.
2. Let _n_ be the MV of |NonZeroDigit|.
3. Let _a_ be _n_ + _d_.

1. Assert: _x_ is a mathematical value.
1. If _numberFormat_.[[Style]] is *"percent"*, set _x_ be 100 × _x_.
1. <ins>If _x_ = 0, let _magnitude_ be -∞.</ins>
1. <ins>Else, let _magnitude_ be the base 10 logarithm of abs(_x_) rounded down to the nearest integer.</ins>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The floor function is available in the spec, so this could be

1. Let _magnitude_ be the floor of the base 10 logarithm of abs(_x_).

(I wonder if we should make base-10 logarithms a part of the spec.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Priority Issues

Development

Successfully merging this pull request may close these issues.

3 participants